<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 10/17/14
 * Time: 4:14 PM
 */

namespace Backend\Modules\Note\controllers;
use Backend\Modules\Note\Forms\FormCreateNoteCategory;
use Common\Models\Note\NoteCategory;

class NoteCategoryController extends \BackendController
{
    public $urlNoteCategory = 'note/note-category';

    public function indexAction()
    {

    }

    public function createAction()
    {
        $form = new FormCreateNoteCategory();
        $form->setAction($this->getBackendUrl() . '/' . $this->urlNoteCategory . '/create');

        if($this->request->isPost())
        {
            if($form->isValid($this->request->getPost()) != false)
            {
                $noteCategory = new NoteCategory();
                $dataPost = $this->request->getPost();
                $noteCategory->assign($dataPost);
                if($noteCategory->save())
                {
                    return $this->response->redirect($this->getBackendUrl() . '/' . $this->urlNoteCategory);
                }
                $this->flash->error($noteCategory->getMessages());
            }
        }
        $this->view->form = $form;
    }
} 